package online_handler

import (
	"fmt"
	"net/http"
	"peilian-api/app/global/bind"
	"peilian-api/app/global/log"
	"peilian-api/app/services/wx_service"
	"peilian-api/utils/format"

	"github.com/gin-gonic/gin"
)

type MsgReq struct {
	Msg string `json:"msg"`
}

type ParamReq struct {
	// Param map[string]interface{} `json:"param"`
	Version int64  `json:"version"`
	Msg     string `json:"msg"`
	Sign    string `json:"sign"`
	KdtName string `json:"kdt_name"`
}

type DeliverOrder struct {
	ExpressState int `json:"express_state"`
	PkId         int `json:"pk_id"`
	ExpressType  int `json:"express_type"`
}

type WeAppLinkReq struct {
	Path  string `json:"path" form:"path"`
	Query string `json:"query" form:"query"`
}

func GetWeAppLinkUrl(c *gin.Context) {
	var req WeAppLinkReq
	if err := bind.ShouldBinding(c, &req); err != nil {
		format.NewResponseJson(c).Err(30001, err.Error())
		return
	}

	wx := new(wx_service.WxService)
	scheme, err := wx.GetWeAppSchema(req.Path, req.Query)
	if err != nil {
		format.NewResponseJson(c).ErrObj(http.StatusBadRequest, err.Error())
		return
	}
	format.NewResponseJson(c).SuccessObj(scheme)
}

func YzMsgCall(ctx *gin.Context) {
	var mr ParamReq
	if err := bind.ShouldBinding(ctx, &mr); err != nil {
		format.NewResponseJson(ctx).Err(30001, err.Error())
		return
	}

	log.Logger.InfoMsgF(ctx, fmt.Sprintf("msg:%v, version:%v, sign:%v, kdtname:%v", mr.Msg, mr.Version, mr.Sign, mr.KdtName))
	ctx.JSON(http.StatusOK, gin.H{
		"code": 0,
		"data": struct{}{},
		"msg":  "success",
	})
}
